package com.qfedu.filter;

import com.qfedu.bean.Users;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author:zhengyilong
 * @email:1797344574@qq.com
 * @phone:13479394730
 * @desc:
 * @DateTime:2022/5/3 11:31
 **/
@WebFilter("/serviceManager/*")
public class CheckFilter_serviceManager implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        //获取session对象
        HttpSession session = request.getSession();

        if (session.getAttribute("user") == null){
            response.sendRedirect("/login.jsp");
        }else if (((Users)session.getAttribute("user")).getStatus() == 4){
            filterChain.doFilter(request,response);
        }else {
            response.sendRedirect("/login.jsp");
        }
    }

    public void destroy() {

    }
}

